<template>
	<div>
		<div>
			<span class='m-l-20'>
				<el-input size='mini' placeholder='设备号' v-model='filter.deviceNo' style='width:200px'></el-input>
			</span>
			<span class='m-l-20'>
				<el-button size='mini' type='primary' icon='el-icon-search' @click='search'>搜索</el-button>
			</span>
		</div>
		<section class='m-t-50 content-box'>
			<el-table style='width:100%;font-size:12px;' ref='multipleTable' :data='listData'>
				<el-table-column label='设备号'>
					<template slot-scope='scope'>{{ scope.row.deviceNo }}</template>
				</el-table-column>
				<el-table-column label='上传者'>
					<template slot-scope='scope'>{{ scope.row.op_user_account }}</template>
				</el-table-column>
				<el-table-column label='版本' align='center'>
					<template slot-scope='scope'>{{ scope.row.version }}</template>
				</el-table-column>
				<el-table-column label='升级时间' align='center'>
					<template slot-scope='scope'>{{ scope.row.upgrade_time | parseTime}}</template>
				</el-table-column>
			</el-table>
			
			<div class='m-t-30'>
				<pagination ref='pagination' :query='pageQuery' v-on:page='listData=$event' url='upgrade/getUpgradeHistoryList'></pagination>
			</div>
		</section>
		
	</div>
</template>

<script>
	import pagination from '@/components/pagination.vue'
	import { Request, confirm, successToast, errorToast } from '@/utils'
	
	let request = new Request()
	
	export default {
		name : 'price',
		data () {
			return {
				filter : {
					status : '',
					version : ''
				}, 
				
				pageQuery : {
					
				},
				
				useStatus : {0 : "未使用", 2 : "已使用"},
				
				listData : [],
				
				showUploadDiaLog : false,
				upgrade : {
					patchPath : '',
					remark : '',
					version : ''
				}
			}
		},
		
		components : {
			pagination
		},
		
		methods : {
			search : function(){
				let filter = Object.assign({}, this.filter)
				this.pageQuery = filter
				
				this.$nextTick(() => {
					this.$refs.pagination.initPage()
				})
	
			},
			
			openUpgrade : function(){
				this.upgrade.patchPath = ''
				this.upgrade.remark = ''
				this.upgrade.version = ''
				
				if(this.$refs.upload){
					this.$refs.upload.reset()
				}
				
				
				this.showUploadDiaLog = true
			},
			
			submit : function(rows){
				let data = this.upgrade
				if(data.patchPath === ''){
					errorToast('请选择升级包', this)
					return
				}
				
				if(data.version === ''){
					errorToast('请填写版本号', this)
					return
				}
				
				request.post('upgrade/addUpgradePatch', res => {
					if(res.code == 0){
						this.showUploadDiaLog = false
						successToast('上传成功', this)
						this.$refs.pagination.getPage()
					}else{
						errorToast(res.msg, this)
					}
				}, data)
				
			},
			
			deletePrice : function(priceId){ //删除代理商
				confirm.call(this, '确定删除该价格套餐吗', () => {
					request.delete('priceCombo/priceDelete?priceId=' + priceId, res => {
						if(res.code == 0){
							successToast('删除成功', this)
							this.$refs.pagination.getPage()
						}else{
							errorToast(res.msg, this)
						}
					})
				})
			}
				
		}
	}
</script>